package com.wzy.controller;

import com.wzy.annotation.LimitRequest;
import com.wzy.annotation.SystemLog;
import com.wzy.domain.ResponseResult;
import com.wzy.domain.bo.CommentBO;
import com.wzy.domain.entity.Comment;
import com.wzy.domain.vo.PageVO;
import com.wzy.domain.vo.UpdateCommentVO;
import com.wzy.service.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.wzy.constant.SystemConstants.DEFINED;

@RestController
@RequiredArgsConstructor
@RequestMapping("/comment")
public class CommentController
{
    private final CommentService commentService;

    /**
     * 查询评论列表
     */
    @GetMapping("/commentList")
    @SystemLog(basenessName = "查询评论列表")
    public ResponseResult<PageVO> commentList(CommentBO commentBO)
    {
        return commentService.getCommentList(commentBO);
    }

    /**
     * 保存评论
     */
    @PostMapping("/saveComment")
    @LimitRequest(time = 60 * 1000, count = 2, type = "USER", tip = DEFINED, description = "休息一下再评论吧~")
    @SystemLog(basenessName = "保存评论")
    public ResponseResult<Void> sendComment(@Validated @RequestBody Comment comment)
    {
        return commentService.saveComment(comment);
    }

    /**
     * 查询友链评论
     */
    @GetMapping("/linkCommentList")
    @SystemLog(basenessName = "查询友链评论")
    public ResponseResult<PageVO> linkCommentList(CommentBO commentBO)
    {
        return commentService.getLinkCommentList(commentBO);
    }

    /**
     * 管理员查询评论
     */
    @GetMapping("/allCommentList")
    @SystemLog(basenessName = "管理员查询所有评论")
    public ResponseResult<PageVO> allCommentList(CommentBO commentBO)
    {
        return commentService.getAllCommentList(commentBO);
    }

    /**
     * 置顶/取消置顶文章评论
     */
    @PutMapping("/setCommentTop/{id}/{label}")
    @SystemLog(basenessName = "置顶/取消置顶文章评论")
    public ResponseResult<Void> setCommentLabel(@PathVariable Long id, @PathVariable String label)
    {
        return commentService.setCommentLabel(id, label);
    }

    /**
     * 管理员删除评论
     */
    @DeleteMapping("/deleteComment/{id}")
    @SystemLog(basenessName = "管理员删除评论")
    public ResponseResult<Void> deleteComment(@PathVariable Long id)
    {
        return commentService.deleteComment(id);
    }

    /**
     * 用户删除评论
     */
    @DeleteMapping("/deleteMyComment/{id}")
    @SystemLog(basenessName = "用户删除评论")
    public ResponseResult<Void> deleteMyComment(@PathVariable Long id)
    {
        return commentService.deleteMyComment(id);
    }

    /**
     * 更新评论用户信息
     */
    @PutMapping("/updateComment")
    @SystemLog(basenessName = "更新评论用户信息")
    public ResponseResult<Void> updateComment(@RequestBody UpdateCommentVO updateCommentVO)
    {
        return commentService.updateComment(updateCommentVO);
    }

}
